package yuekao1.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.functions.sink.RichSinkFunction;
import org.apache.flink.streaming.api.functions.sink.SinkFunction;
import redis.clients.jedis.Jedis;
//redis-server redis.conf
//redis-cli --raw
public class RedisUtil extends RichSinkFunction<String> {
    Jedis jedis=null;

    @Override
    public void open(Configuration parameters) throws Exception {
        jedis = new Jedis("hadoop-single", 6379);
    }
    @Override
    public void close() throws Exception {
        jedis.close();
    }

    @Override
    public void invoke(String value, Context context) throws Exception {
        //键值对
        JSONObject jsonObject = JSON.parseObject(value);
        String key = jsonObject.getString("tb") + ":" + jsonObject.getJSONObject("data").getString("id");
        jedis.set(key,value);
    }
}
